 function y = sum_square( x, dim )

%SUM_SQUARE   Sum of squares.
%   For vectors, SUM_SQUARE(X) is the sum of the squares of the elements of
%   the vector; i.e., SUM(X.^2).
%
%   For matrices, SUM_SQUARE(X) is a row vector containing the application
%   of SUM_SQUARE to each column. For N-D arrays, the SUM_SQUARE operation
%   is applied to the first non-singleton dimension of X.
%
%   SUM_SQUARE(X,DIM) takes the sum along the dimension DIM of X.
%
%   Disciplined convex programming information:
%       If X is real, then SUM_SQUARE(X,...) is convex and nonmonotonic in
%       X. If X is complex, then SUM_SQUARE(X,...) is neither convex nor
%       concave. Thus, when used in CVX expressions, X must be affine. DIM
%       must be constant.

error( nargchk( 1, 2, nargin ) );
y = x .* x;
if nargin == 2,
    y = sum( y, dim );
else
    y = sum( y );
end

% Copyright 2008 Michael C. Grant and Stephen P. Boyd.
% See the file COPYING.txt for full copyright information.
% The command 'cvx_where' will show where this file is located.
%function b = sum_square(numProj,angle,x,Msize)



% L = numProj;
% width = Msize;
% N = width;
% thc = linspace(0, pi-pi/L, L);
% thc = thc(angle);
% angleLength = length(angle);
% b = zeros(angleLength*Msize,1);
% Row = zeros(1,length(x));
%   
% for ll = 1:angleLength
% 
% 	if ((thc(ll) <= pi/4) | (thc(ll) > 3*pi/4))
% 		yr = round(tan(thc(ll))*(-N/2+1:N/2-1))+N/2+1;
% %       for nn = 1:N-1
% %       	M(yr(nn),nn+1) = 1;
% %         for index = 1 : width
% %             if ((yr(nn)-1 + index - width/2 ) < width&&(yr(nn)-1 + index - width/2 )>=0)
% %             MeatureMatrix((ll-1)*width + index,(yr(nn)-1 + index - width/2 )*N   + nn + 1)=1;
% %             end
% %         end
%           for index = 1:width
%               %form a row
%               for nn = 1:N-1
%                   if ((yr(nn)-1 + index - width/2 ) < width&&(yr(nn)-1 + index - width/2 )>=0)
%                       Row ((yr(nn)-1 + index - width/2 )*N   + nn + 1) = 1;
%                   end   
%               end
%               %sample
%               b((ll-1)*width + index)= Row * x;
%               Row(:) = 0;
%           end
%       
%   else 
% 		xc = round(cot(thc(ll))*(-N/2+1:N/2-1))+N/2+1;
% % 		for nn = 1:N-1
% % 			M(nn+1,xc(nn)) = 1;
% %             for index = 1 : width
% %                 if((xc(nn)+ index - width/2)<width&&(xc(nn)+ index - width/2)>=0)
% %                     MeatureMatrix((ll-1)*width+index,(nn+1-1)*N + xc(nn)+ index - width/2)=1;
% %                 end
% %             end
% % 		end
%           for index = 1:width
%               %form a row
%               for nn = 1:N-1
%                  if((xc(nn)+ index - width/2)<width&&(xc(nn)+ index - width/2)>=0)
%                       Row ((nn+1-1)*N + xc(nn)+ index - width/2) = 1;
%                   end   
%               end
%               %sample
%               b((ll-1)*width + index)= Row * x;
%               Row(:) = 0;
%           end
% 
%   end
% 
% end
% 
